package com.gingko.duominuo.viewmodel

import androidx.hilt.Assisted
import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.SavedStateHandle
import com.gingko.duominuo.data.Resource
import com.gingko.duominuo.data.asResource
import com.gingko.duominuo.data.isSuccess
import com.gingko.duominuo.data.model.WorkOrderVo
import com.gingko.duominuo.data.request.OrderDetailReqVo
import com.gingko.duominuo.data.request.OrderReqVo
import com.gingko.duominuo.data.source.repository.GinkgoRepository

class WorkOrderRecordViewModel @ViewModelInject constructor(
    private val ginkgoRepository: GinkgoRepository,
    @Assisted
    val state: SavedStateHandle
) : BaseViewModel() {
    private val _workOrderLiveData = MutableLiveData<Resource<List<WorkOrderVo>>>()
    val workOrderLiveData: LiveData<Resource<List<WorkOrderVo>>> = _workOrderLiveData

    fun getWorkOrderRecord() {
        launchOnUI(
            task = {
                val data = ginkgoRepository.getWorkOrder(OrderReqVo()).data?.list_order ?: listOf()
                _workOrderLiveData.value = Resource.Success(data)
            },
            onFailure = {
                _workOrderLiveData.value = Resource.Error(it)
            }
        )

    }


}